using System;
using System.Collections.ObjectModel;
using System.Threading;
using System.Windows;
using SalesPoint.Model;
using SalesPoint.Views;
using SalesPoint.Security;
using Xtensive.Orm;

namespace SalesPoint.ViewModels
{
  public class ProductListViewModel : GenericListViewModel<Product>
  {
    protected override Product CreateItem()
    {
      return new Product(Session);
    }

    protected override Window GetItemView()
    {
      return new ProductItemView();
    }

    protected override GenericItemViewModel<Product> GetItemViewModel()
    {
      return new ProductItemViewModel(Session, Item);
    }

    protected override ObservableCollection<Product> GetItems()
    {
      var query = Session.Query.All<Product>()
        .Prefetch(p => p.Category)
        .Prefetch(p => p.Supplier);

      return new ObservableCollection<Product>(query);
    }

    public ProductListViewModel(Session session)
      : base(session, "Products")
    {
    }
  }
}
